package com.zjgeport.zjgdanger.Exception;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.zjgeport.zjgdanger.CommonActivity;
import com.zjgeport.zjgdanger.R;

public class IllegalMainActivity extends FragmentActivity {
    private Fragment fragment[];
    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;
    private Button unappr;
    private Button appr;
    private String flag;
    private EditText searchText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_illegal_main);
        initView();
    }

    private void initView()
    {
        ((Button)findViewById(R.id.back)).setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                finish();
            }
        });
        unappr = (Button) findViewById(R.id.uncheck_water);
        appr = (Button) findViewById(R.id.check_water);

        flag = "0";

        fragmentManager = getSupportFragmentManager();
        fragment = new Fragment[2];

        fragment[0] = fragmentManager.findFragmentById(R.id.fragement_illegalundo);
        fragment[1] = fragmentManager.findFragmentById(R.id.fragement_illegaldo);
        fragmentTransaction = fragmentManager.beginTransaction().hide(fragment[0]).hide(fragment[1]);
        fragmentTransaction.show(fragment[0]).commit();

        unappr.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                flag = "0";
                fragmentTransaction = fragmentManager.beginTransaction().hide(fragment[0]).hide(fragment[1]);
                fragmentTransaction.show(fragment[0]).commit();
                unappr.setBackgroundResource(R.color.theme_color);
                appr.setBackgroundResource(R.color.theme_color);
                unappr.setTextColor(getResources().getColor(R.color.white));
                appr.setTextColor(getResources().getColor(R.color.tab_nor));
            }
        });

        appr.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                flag = "1";
                fragmentTransaction = fragmentManager.beginTransaction().hide(fragment[0]).hide(fragment[1]);
                fragmentTransaction.show(fragment[1]).commit();
                unappr.setBackgroundResource(R.color.theme_color);
                appr.setBackgroundResource(R.color.theme_color);
                unappr.setTextColor(getResources().getColor(R.color.tab_nor));
                appr.setTextColor(getResources().getColor(R.color.white));
            }
        });

        searchText = findViewById(R.id.search_content1);
        searchText.setHint("请输入储罐代码或公司名称");
        searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                if ((actionId == 0 || actionId == 3) && event != null) {

                    Intent intent = new Intent("android.text_change");
                    intent.putExtra("flag", flag);
                    intent.putExtra("keyword",searchText.getText().toString());
                    sendBroadcast(intent);
                }
                return false;
            }
        });

    }

    public String getflag() {
        return flag;
    }

    public void setflag(String flag) {
        this.flag = flag;
    }

}
